from multiprocessing import Queue, Process
import time

def consumer(queue):
    for i in range(5):
        data = f"数据-{i}"
        queue.put(data)
        print(f"往队列中放入：{data}")
        time.sleep(0.5)
    queue.put(None)
    print("放入数据完毕")

def producer(queue):
    while True:
        data = queue.get()
        if data is None:
            print("队列数据已全部取出")
            break
        print(f"从队列中取出数据：{data}")
        time.sleep(0.5)

if __name__ == '__main__':
    q = Queue()
    p = Process(target = consumer, args = (q, ))
    p.start()
    p.join()
    producer(q)